const {
  request
} = require("../../utils/index.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    Eliteshare:{
      pageNum:1,  //页码
      pageSize:10,   //每页条数
      searchLabel:'heat',  //搜索标签
      searchName:'',  //名称查询
    },
    resultList:[],  //首页精英分享推荐数据
    mess:0, //消息
  },
  async login(){
    let that=this;
    wx.login({
      success: async function (res) {
        if (res.code) {
          let params = {
            url: "hw/portal/user/wechat/login",
            method: "POST",
            data: {
              wxCode: res.code 
            }
          }
          let result = await request(params);
          if (result.status == 100) {
            wx.setStorageSync('token', result.data.token)  
            wx.setStorageSync('userId', result.data.userId)
            wx.setStorageSync('mess', result.data.msgUnReadCount)
            that.setData({
              mess:wx.getStorageSync('mess'),
              token: wx.getStorageSync('token')
            })
            that.init();
          } else {
          }
        } else {
          console.log('登录失败！' + res.errMsg)
        }
      }
    })
  },
  // 精英分享推荐列表
  async init(){
    try {
      let that = this;
      let par = {
        url: "hw/portal/articles/ds/recommend?token="+wx.getStorageSync('token'),
        method: "GET",
        header:{
          "Content-Type":"application/json"
        }
      }
      let datainfo = await request(par);
      if(datainfo.status==100){
        that.setData({
          resultList:datainfo.data
        })
      }
    } catch (error) {
      console.log(error);
    }
  },
  release:function(option){
    wx.navigateTo({
      url: '../../pages/Commrelease/releases',
    })
  },

  Mutualinfo:function(option){
    wx.navigateTo({
      url: '../../pages/Mutual/Mutualinfo',
    })
  },

  share:function(potions){
    wx.navigateTo({
      url: '../elite_share/shares',
    })
  },

  coopera:function(potions){
    wx.navigateTo({
      url: '../Recruicoop/Recruicoop',
    })
  },

  called:function(potion){
    wx.navigateTo({
      url: '../called/called',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if(parseInt(this.data.mess)>99){
      this.setData({
        mess:"99+"
      })
    }
    this.onShareTimeline();
  },
  
  onShareTimeline: function () {
		return {
	      title: '浩瀚广维',
	      query: {
	      }, 
        imageUrl: ''
	    }
	},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    //this.GetHight();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: async function () {
    await this.login();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.init();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
   onReachBottom: function () {
  //   wx.showNavigationBarLoading(); //显示加载
  //   //模拟加载  1秒
  //   let that = this;
  //   if(this.data.Eliteshare.pageNum >= this.data.resultList.lastPage){
  //     wx.showToast({
  //       title: '滑倒底了',
  //       icon:"none"
  //     })
  //     wx.hideNavigationBarLoading();  //停止加载
  //     return;
  //   }
  //   this.setData({
  //     "Eliteshare.pageNum":++this.data.Eliteshare.pageNum
  //   })
  //   let par = {
  //     url:"hw/portal/articles/ds/recommend?token=" + wx.getStorageSync('token'),
  //     method:"GET",
  //     data:that.data.Eliteshare,
  //     header: {
  //       "Content-Type": "application/json"
  //     },
  //   }
  //   let datainfo = await request(par);
  //   if(datainfo.data != undefined){
  //     let lao = that.data.resultList.list //将老数据存入
  //     if(datainfo.data.list){
  //       let list = [...lao,...datainfo.data.list]  //新老数据拼接
  //       that.setData({
  //         resultList:datainfo.data,  //重新赋值
  //         "resultList.list": list
  //       })
  //     }
  //   }else{
  //     // 滑倒底了
  //   }
  //   wx.hideNavigationBarLoading(); //停止加载
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})